import 'package:flutter/material.dart';

class HomeNav extends StatelessWidget {
  const HomeNav({Key? key, required this.navList}) : super(key: key);
  final List navList;
  @override
  Widget build(BuildContext context) {
    //GridView
    return GridView.builder(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 5,
          mainAxisSpacing: 0,
          crossAxisSpacing: 0,
          childAspectRatio: 1,
        ),
        itemCount: navList.length,
        shrinkWrap: true,
        itemBuilder: (context, index) {
          return Container(
            color: Colors.white,
            alignment: Alignment.center,
            child: Container(
              child: Column(
                children: [
                  //使用Expanded组件可以解决文字超出区域溢出的问题
                  Expanded(
                      child: Image.network(
                    navList[index]['imgUrl'],
                    width: 60,
                    height: 60,
                    fit: BoxFit.cover,
                  )),
                  Expanded(
                      child: Text(
                    navList[index]['text'],
                    style: TextStyle(fontSize: 13),
                  ))
                ],
              ),
            ),
          );
        });
  }
}
